#! /usr/bin/python2.7
import sys
import time
import pexpect

#file = open('log.txt', 'w')
#sys.stdout = file

#handle running config More
def showRun(child):
    try:
	while True:
	    child.expect('More')
	    child.send(' ')
    except pexpect.exceptions.TIMEOUT:
    	child.expect("R1.*")


def Main():
    """
         This is Main Entry 
    """
     
    child = pexpect.spawn("telnet 10.1.5.254",logfile=sys.stdout, timeout=3)
    child.expect("Username.*")
    child.sendline("cisco")
    child.expect("Password")
    child.sendline("cisco")
    child.expect("R1.*")
    child.sendline("enable")
    child.expect("Password.*")
    child.sendline("cisco")
    child.expect("R1#")
    child.sendline("config t")
    child.expect("config.*")
    child.sendline("interface f0/0")
#    child.expect("R1.*")

    while True:
        child.sendline("ip ospf hello-interval 20")
        child.expect("R1.*")
        time.sleep(3)
        child.sendline("do show run")
        showRun(child)
        child.sendline("do show run")
        showRun(child)
        child.sendline("ip ospf hello-interval 10")
        child.expect("R1.*")
        time.sleep(3)

if __name__ == '__main__':
    Main()
